package com.gxan.service.impl;

import com.gxan.common.R;
import com.gxan.dao.UserDao;
import com.gxan.dao.impl.UserDaoImpl;
import com.gxan.pojo.User;
import com.gxan.service.UserService;

import java.sql.SQLException;

public class UserServiceImpl implements UserService {
    @Override
    public R login(String username, String password) {
        //先调用dao查询出结果，看是否存在用户
        R<User> userR = new R<User>();
        UserDao userDao = new UserDaoImpl();
        try {
            User user = userDao.findUserByUsernameAndPwd(username, password);
            //用户存在
            if(user!=null){
                userR.setCode(200);
                userR.setMsg("登录成功");
                userR.setData(user);
            }else{
                //不成功，表示账号或者密码错误
                userR.setCode(500);
                userR.setMsg("账号或密码错误");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return userR;

    }
}
